//
//  SelectSeatTopView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/13.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class SelectSeatTopView: UIView {
    
    private var subseartTops = [SubSeatTopView]()
    private let titles = ["选中","未选","不可选","紧急出口"]
    private let pics = ["selected","unselect","seatlock","seatexit"]
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        init_view()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func init_view() -> Void {
        (0..<pics.count).forEach { (i) in
            subseartTops.append(SubSeatTopView())
        }
    }
    
    override func layoutSubviews() {
        if subseartTops.count == 0 {
            return
        }
        let w = frame.width / 4
        for i in 0..<pics.count {
            let subSeatTop = subseartTops[i]
            subSeatTop.name = pics[i]
            subSeatTop.title = titles[i]
            subSeatTop.frame = CGRect(x: w * CGFloat(i), y: 0, width: w, height: frame.height)
            addSubview(subSeatTop)
        }
    }
    
    class SubSeatTopView: UIView {
        
        // 图片
        private let img = UIImageView()
        //  文本
        private  let label = UILabel(title: "测试", color: COLOR_NICE, size: 13, align: .center)
        
        public var name:String? {
            didSet {
                img.image = UIImage(named: name!)
            }
        }
        public var title:String? {
            didSet {
                label.text = title
            }
        }
        
        override func layoutSubviews() {
            // 图片
            let imgX = (frame.width - MARGIN25) * 0.5
            img.frame = CGRect(x: imgX, y: MARGIN20, width: MARGIN25, height: MARGIN25)
            addSubview(img)
            //  文本
            label.frame = CGRect(x: 0, y: img.frame.maxY + MARGIN5, width: frame.width, height: MARGIN)
            addSubview(label)
        }
    }
}
